//
// Description: 69. x 的平方根
// Created by Loading on 2025/4/7.
//

#include <bits/stdc++.h>

using namespace std;

int mySqrt(int x) {
    int l = 0, r = x;
    // 二分查找 合适的值
    while (l <= r) {
        int mid = l + (r - l) / 2;
        /// 要使用乘法，转换为8字节，使用除法会出现除数为0的问题
        if ((long long) mid * mid > x) {
            r = mid - 1;
        } else {
            l = mid + 1;
        }
    }

    return l - 1;
}

int main() {
    int x = 2145382131;

    int res = mySqrt(x);

    cout << res << endl;

    return 0;
}
